<?php
class Log extends Admin_Controller
{
	
	function __construct()
	{
		parent::__construct();
		$this->load->model('log_model','log');
	}
	
	function index()
	{
		$where = ' 1 = 1 ';
		if(!empty($_GET['search']))$where .= 'and detail like \'%'.$_GET['search'].'%\'';
		if(!empty($_GET['ip']))$where .= 'and ip = \''.$_GET['ip'].'\'';
		if(!empty($_GET['name']))$where .= 'and (users.firstname like \'%'.$_GET['name'].'%\' or users.lastname like \'%'.$_GET['name'].'%\')';
		if(!empty($_GET['log_date']))$where .= 'and date(cast(\'1970-01-01-00.00.00.0\' as timestamp) + log_date seconds) = cast(\''.date_to_mysql($_GET['log_date'],TRUE).'\' as date)';
		$data['result'] = $this->log->where($where)->order('desc')->get();
		$data['pagination'] = $this->log->pagination();
		$this->template->append_metadata(js_datepicker());
		$this->template->build('log_index',$data);
	}
	
	public function create_table()
	{
		$sql = '		
		CREATE TABLE DB2INST1.LOGS
		(
		ID INTEGER,
		USER_ID INT,
		IP VARCHAR(250),
		LOG_DATE BIGINT,
		DETAIL LONG VARCHAR
		)
		';
		echo ($this->db->execute($sql)) ? 'Success' : 'Fail';
	}
	
}
?>